package com.siganet.xgdemo;

import com.tencent.android.tpush.XGIOperateCallback;
import com.tencent.android.tpush.XGPushManager;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);

//		EditText editText = (EditText) findViewById(R.id.editText1);
		Button b1 = (Button) findViewById(R.id.button1);
		Button b2 = (Button) findViewById(R.id.button2);
		Button b3 = (Button) findViewById(R.id.button3);

		XGPushManager.registerPush(this, new XGIOperateCallback() {

			@Override
			public void onSuccess(Object data, int flag) {
				Log.d("yet", "注册成功，设备token为：" + data);
				Toast.makeText(getApplicationContext(), "注册成功，设备token为：" + data, Toast.LENGTH_SHORT).show();
			}

			@Override
			public void onFail(Object data, int errCode, String msg) {
				Log.d("yet", "注册失败，错误码：" + errCode + ",错误信息：" + msg);
				Toast.makeText(getApplicationContext(), "注册失败，错误码：" + errCode + ",错误信息：" + msg, Toast.LENGTH_SHORT)
						.show();
			}
		});

		b1.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				EditText editText1 = (EditText) findViewById(R.id.editText1);
				String username = editText1.getText().toString();

				XGPushManager.registerPush(getApplicationContext(), username, new XGIOperateCallback() {

					@Override
					public void onSuccess(Object data, int flag) {
						Log.d("yet", "绑定成功，设备token为：" + data);
						Toast.makeText(getApplicationContext(), "绑定成功，设备token为：" + data, Toast.LENGTH_SHORT).show();
						XGPushManager.setTag(getApplicationContext(), "sgnet_19");
						Toast.makeText(getApplicationContext(), "绑定标签成功", Toast.LENGTH_SHORT).show();
					}

					@Override
					public void onFail(Object data, int errCode, String msg) {
						Toast.makeText(getApplicationContext(), "绑定成功，错误码：" + errCode + ",错误信息：" + msg, Toast.LENGTH_SHORT)
						.show();
					}
				});
			}
		});

		b2.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				XGPushManager.registerPush(getApplicationContext(), "*", new XGIOperateCallback() {

					@Override
					public void onSuccess(Object data, int flag) {
						Log.d("yet", "解绑成功");
						Toast.makeText(getApplicationContext(), "解绑成功", Toast.LENGTH_SHORT).show();
					}

					@Override
					public void onFail(Object data, int errCode, String msg) {
						Log.d("yet", "解绑失败");
						Toast.makeText(getApplicationContext(), "解绑失败", Toast.LENGTH_SHORT).show();
					}
				});
			}
		});

		b3.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				Intent intent = new Intent(getApplicationContext(),TActivity.class);
				startActivity(intent);
			}
		});
	}
}
